package cn.wolfcode.luowowo.website.web.advice;

import cn.wolfcode.luowowo.common.exception.LogicException;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理类
 */
@ControllerAdvice
public class CommentException {
    /**
     * 前端页面Ajax调用过来如果抛出自己的异常,来到这里
     * @param e
     * @return
     */
    @ExceptionHandler(LogicException.class)
    @ResponseBody
    public Object LogicException(Exception e){
            return new AjaxResult(false,e.getMessage());
    }
    /**
     * 前端页面Ajax调用过来如果是系统异常,来到这里
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Object RunTimeException(Exception e){
             e.printStackTrace();
            return new AjaxResult(false,"系统繁忙,请稍后重试");
    }
}
